package yqt.com.cnki.controller;


import haha.life.common.CutPageBean;
import haha.life.common.SysTool;
import haha.life.normal.CommonConvertUtils;
import haha.life.normal.FileUtil;
import io.swagger.annotations.ApiOperation;
import jzqb.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yqt.com.cnki.bo.QBZXBo;
import yqt.com.cnki.po.QBZXPo;
import yqt.com.cnki.service.IQBZXService;

import java.util.List;
import java.util.Map;

/**
 * Description: 情报资讯-业务层(热点透视)
 *
 * @author BaiGe
 * @date: 2021/11/10 15:18
 * @Version 1.0
 */
@RestController
@RequestMapping("/qbzx")
public class QBZXController {
    @Autowired
    private IQBZXService qbzxService;


    @ApiOperation(value = "获取情报资讯分类名")
    @GetMapping("/getSortName")
    public Result getSortName() {
        return Result.succ(qbzxService.getSortNameFromDB());
    }

    @ApiOperation(value = "情报资源图片来源")
    @GetMapping("/getPngSource")
    public Result getPngSource() {
        String xmlStr = FileUtil.readJsonFile("yqtConfig.xml");
        Map<String, String> requestMap = CommonConvertUtils.getXMLStringValue(xmlStr);
        // 获取指定标签值
        String s = requestMap.get("情报资源图片来源");
//        String[] sourceArr = s.split(",");
        return Result.succ(s);
    }


    @ApiOperation(value = "根据分类名展示情报资讯-包含展示五条和more按钮")
    @PostMapping("/getQBZXBySortName")
    public Object getQBZXBySortName(@RequestBody QBZXBo qbzxBo) {
        Integer isLimitFive = qbzxBo.getIsLimitFive();
        if (isLimitFive == 0) { //首页只显示五条,不分页
            List<QBZXPo> qbzxPoList = qbzxService.getQBZXBySortName_LimitFive(qbzxBo);
            return  qbzxPoList;
        } else  {
            CutPageBean<QBZXPo> cutPage = qbzxService.getQBZXBySortName_CutPage(qbzxBo);
            return cutPage;
        }
    }


    @ApiOperation(value = "获取封面路径")
    @PostMapping("/getCover")
    public Result getCover(@RequestBody Map<String, String> map) {
        String source = map.get("source");
        List<Map<String, String>> cover = qbzxService.getCover(source);
        return Result.succ(cover);
    }

}
